﻿using System.Collections.Generic;

namespace IceCS.DesignPattern.Core.IteratorPattern.NameSystem
{
    public class NameRepository : IContainer
    {
        private class NameIterator : IIterator
        {
            private int _index;
            private readonly NameRepository _container;
            public NameIterator(NameRepository container)
            {
                _index = 0;
                _container = container;
            }
            public bool HasNext() => _index < _container.NamesList.Count;

            public string Next()
            {
                if (!HasNext()) { return null; }
                var name = _container.NamesList[_index];
                _index += 1;
                return name;
            }

            public string CurrentName => _container.NamesList[_index];
        }
        public List<string> NamesList { get; set; }
        public NameRepository()
        {
            NamesList = new List<string>
            {
                "Robert" ,
                "John" ,
                "Julie" ,
                "Lora"
            };
        }
        public IIterator GetIterator()
        {
            return new NameIterator(this);
        }
    }
}
